// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  traceUser: true,
  env:'aaa111-9gh9fp5ieac4de5d'
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const tripId = event.tripId
    //查询绑定的dayId
    await db.collection('trip').where({
        _id: tripId
    }).get().then(res=>{
        const days = res.data[0].days
        console.log(tripId, days)
        //删除day
        for (var i = 0; i<days.length; i++) {
            db.collection('tripDays').where({
                _id: days[i]
            }).remove()
        }
        //删除trip
        db.collection('trip').where({
            _id: tripId
        }).remove()
    })

    return true
}